package com.backend.springboot_project_demo.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class User {
    private final static int NEGATIVE_ONE = -1;
    private final static int ZERO = 0;
    private final static int ONE = 1;
    private final static String FEMALE = "女";
    private final static String MALE = "男";
    private final static String ACTIVE = "有效";
    private final static String INACTIVE = "失效";
    private final static String ERROR = "错误信息请重新设置";
    private String id;
    private String username;
    private String password;
    private String roleId;
    private int sex;
    private int status;
    private String address;
    private String createTime;
    private String updateTime;

    public boolean isPassValidation () {
        return !this.id.isBlank() && status != ZERO;
    }

    public UserTransfer toUserTransfer() {
        return new UserTransfer(
                this.id,
                this.username,
                this.password,
                this.roleId,
                chooseSex(this.sex),
                chooseStatus(this.status),
                this.address,
                this.createTime,
                this.updateTime,
                NEGATIVE_ONE,
                NEGATIVE_ONE
        );
    }

    private String chooseSex(int sex) {
        if (ZERO == sex) {
            return MALE;
        } else if (ONE ==sex) {
            return FEMALE;
        } else {
            return ERROR;
        }
    }

    private String chooseStatus(int status) {
        if (ZERO == status) {
            return ACTIVE;
        } else if (ONE == status) {
            return  INACTIVE;
        } else {
            return ERROR;
        }
    }
}
